/**
* @Description: 活动规则 -- 详情
* @author  tangbin
* @date 2023/3/20
*/

<template>
  <div class="mh100">
    <div class="page-container" style="overflow: scroll;" v-loading="pageLoading">
      <div class="split-content-info" id="ruleTop">
        <!-- 标题 -->
        <div class="split-content-title clearfix">
          <div class="split-title">
            <span style="display:inline-block; background-color: #1890FF;margin-bottom: -2px; margin-right: 8px; width: 3px; height: 14px"></span>
            <span style="display: inline-block; color: #333333; font-size: 16px;">基本信息</span>
          </div>
        </div>
        <div>
          <el-descriptions class="margin-top" :column="3" border>
          <el-descriptions-item labelStyle="width: 150px" contentStyle="width: 250px" label="限制类型">{{ getLimitType(form.limitType) }}</el-descriptions-item>
          <el-descriptions-item labelStyle="width: 150px" contentStyle="width: 250px" label="限制次数">{{ form.limitNum }}</el-descriptions-item>
          <el-descriptions-item labelStyle="width: 150px" contentStyle="width: 250px" label="状态">{{ getStatus(form.status) }}</el-descriptions-item>
          <el-descriptions-item label="备注">{{ form.remark }}</el-descriptions-item>
        </el-descriptions>
        </div>
        
      </div>

      <!-- 模块分割线 -->
      <div class="split-line"></div>
      <!-- 模块分割线 -->
      <div class="split-content-info" :style="{height: height + 'px', minHeight: 130 + 'px'}">
        <div class="split-content-title clearfix">
          <div class="split-title">
            <span style="display:inline-block; background-color: #1890FF;margin-bottom: -2px; margin-right: 8px; width: 3px; height: 14px"></span>
            <span style="display: inline-block; color: #333333; font-size: 16px;">选择客户分类</span>
          </div>
        </div>
        <div style="padding-left: 20px; padding-right: 20px; margin-bottom: 30px;">
          <el-radio-group v-model="form.customerType">
            <el-radio v-for="item in dict.type.basic_data_customer_type" :label="item.value" :disabled="form.customerType !==  item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </div>
          

      </div>

      


      <div class="h84_line"></div>
      <div class="bottom-btn">
        <div class="bottom-locate" >
          <el-button type="primary" @click="cancel">返回</el-button>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import {activityRuleDetail} from '@/api/basic/activityRule.js'
import {getTimeSeconds} from '@/utils/index.js'

export default {
  name: 'ActivityRuleDetail',
  dicts: ['order_class_status', 'basic_data_customer_type', 'basic_data_limint_type'],
  data() {
    return {
      mountedTime: undefined, // mounted时间
      activatedTime: undefined, // activated时间
      height: 130,
      ruleId: this.$route.query.ruleId,
      pageLoading: false,
      form: {},
    }
  },
  activated() {
    this.tableHeight();
  },
  mounted() {
    this.mountedTime = new Date();
    this.ruleId = this.$route.query.ruleId;
    this.getActivityRuleDetail();
  },
  activated() {
    this.ruleId = this.$route.query.ruleId;
    this.activatedTime = new Date();
    // 得到秒数
    let seconds = getTimeSeconds(this.mountedTime, this.activatedTime);
    if (seconds >= 1) {
      this.getActivityRuleDetail();
    }
  },
  updated() {
    // 解决表格设置固定高度导致列设置fixed后重新进来会错行问题
    this.tableHeight();
    // this.$nextTick(() => {
    //   this.$refs.filterTable.doLayout();
    // });
  },
  methods: {
    
    tableHeight() {
      this.$nextTick(() => {
        let height = document.body.clientHeight - 90 - 40;
        // 查询表单高度
        let s_height = document.getElementById('ruleTop').clientHeight;
        // 按钮容器高度
        // let btns_height = document.getElementById('comTabel').clientHeight;
        // 计算表格的高度
        this.height = height - s_height - 20 - 64;
      });
    },

    /**
     * 获取活动规则详情
     */
     getActivityRuleDetail() {
      if (this.ruleId == undefined) {
        return;
      }
      this.pageLoading = true;
      activityRuleDetail({id: this.ruleId}).then(res => {
        // console.log('res=', res);
        if (res.code === 200) {
          this.form = {...res.data};
          this.pageLoading = false;
        }
      }).catch(err => {

      });
    },

    /**
     * 获取状态啊名称
     * @param {*} value 
     */
    getStatus(value) {
      let show = "";
      this.dict.type.order_class_status.some((item) => {
        if (item.value === value) {
          show = item.label;
          return true;
        }
      });
      return show;
    },

    /**
     * 得到限制类型名称
     * @param {*} value 
     */
    getLimitType(value) {
      let show = "";
      this.dict.type.basic_data_limint_type.some((item) => {
        if (item.value === value) {
          show = item.label;
          return true;
        }
      });
      return show;
    },

    cancel() {
      const obj = { path: "/basicData/ActivityRule" };
      this.$tab.closeOpenPage(obj);
    },
  },
}
</script>

<style lang="scss" scoped>

</style>